<%@page contentType="text/html;charset=utf-8"%>
<%@include file="../../core/common.jsp"%>
<html>
<head>
<title></title>
</head>
<script>
	var index_;
	var row_;
	function find_(index, row) {
		index_ = index;
		row_ = row;
		$('#dg').datagrid('options').url = '${CTX}/mgt/sys/dict/find';
		$('#dg').datagrid('reload', {
			type : row.value
		});
	}
</script>
<body>
	<div id="tb" class="toolbar">
		<div style="float: left;">
			<shiro:hasPermission name="dict:insert">
				<a id="insert" class="form-btn primary">
					<i class="fa fa-plus m-r-5"></i>添加
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="dict:update">
				<a id="update" class="form-btn primary">
					<i class="fa fa-pencil-square-o m-r-5"></i>修改
				</a>
			</shiro:hasPermission>
			<shiro:hasPermission name="dict:delete">
				<a id="delete" class="form-btn danger">
					<i class="fa fa-trash-o m-r-5"></i>删除
				</a>
			</shiro:hasPermission>
		</div>
		<div style="float: right;">
			<a id="find" class="form-btn success">
				<i class="fa fa-refresh m-r-5"></i>刷新
			</a>
		</div>
		<div style="clear: both;"></div>
	</div>
	<div class="easyui-panel" data-options="fit:true,border:false,header:'#tb'">
		<div class="easyui-layout">
			<div data-options="region:'west',border:false,width:250" style="padding: 3px 0px 3px 3px;">
				<ul id="dl" class="easyui-datalist" data-options="title:'字典类型',url:'${CTX}/mgt/sys/dict/option/-1',border:true,onClickRow:find_"></ul>
			</div>
			<div data-options="region:'center',border:false" style="padding: 3px;">
				<table id="dg" class="easyui-datagrid" data-options="border:true">
					<thead>
						<tr>
							<th data-options="field:'code',width:250">字典代码</th>
							<th data-options="field:'name',width:250">字典名称</th>
							<th data-options="field:'sort',width:100">字典顺序</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</div>
</body>
<script>
	$(function() {
		$('#find').click(function() {
			window.location.reload();
		});
		$('#insert').click(function() {
			if (row_) {
				$.open({
					title : $(this).html(),
					url : '${CTX}/mgt/sys/dict/insert?type=' + row_.value,
					end : function() {
						find_(index_, row_);
					}
				});
			} else {
				$.info('请选择字典类型');
			}
		});
		$('#update').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.open({
					title : $(this).html(),
					url : '${CTX}/mgt/sys/dict/update?id=' + row.id,
					end : function() {
						find_(index_, row_);
					}
				});
			} else {
				$.info('请选择数据字典');
			}
		});
		$('#delete').click(function() {
			var row = $('#dg').datagrid('getSelected');
			if (row) {
				$.confirm('确定删除数据字典', function() {
					$.mask();
					$.ajax({
						url : '${CTX}/mgt/sys/dict/delete',
						data : {
							id : row.id
						},
						success : function(data) {
							$.unmask();
							$.handle(data, function() {
								find_(index_, row_);
							});
						}
					});
				});
			} else {
				$.info('请选择数据字典');
			}
		});
	});
</script>
</html>